home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / oleo-1_4.lha / oleo-1.4 / io-edit.c < prev    next >
C/C++ Source or Header  |  1993-05-22  |  16KB  |  938 lines

  1. /*    Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  2.  
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7.  
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. GNU General Public License for more details.
  12.  
  13. You should have received a copy of the GNU General Public License
  14. along with this software; see the file COPYING.  If not, write to
  15. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  16.  
  17.  
  18.  
  19.  
  20. #include "funcdef.h"
  21. #include <stdio.h>
  22. #include <fcntl.h>
  23. #include <errno.h>
  24. #include <ctype.h>
  25.  
  26. #undef NULL
  27.  
  28. #include "sysdef.h"
  29. #include "global.h"
  30. #include "cell.h"
  31. #include "io-utils.h"
  32. #include "io-edit.h"
  33. #include "io-abstract.h"
  34. #include "io-generic.h"
  35. #include "cmd.h"
  36. #include "format.h"
  37. #include "lists.h"
  38. #include "regions.h"
  39.  
  40.  
  41. /* Shorthand */
  42.  
  43. #define the_cursor        the_cmd_arg.cursor
  44. #define the_text         the_cmd_arg.text
  45. #define the_do_prompt        the_cmd_arg.do_prompt
  46. #define the_is_set        the_cmd_arg.is_set
  47. #define the_overwrite        the_cmd_arg.overwrite
  48.  
  49.  
  50.  
  51. /* Editting primitives
  52.  * 
  53.  * Commands that edit arguments to other commands should work by changing
  54.  * the string stored in the_cmd_arg.text.   These functions edit that string
  55.  * and correctly update the display.
  56.  */
  57.  
  58. #ifdef __STDC__
  59. int
  60. check_editting_mode (void)
  61. #else
  62. int
  63. check_editting_mode ()
  64. #endif
  65. {
  66.   if (!the_cmd_frame->cmd || cur_arg >= cmd_argc || !the_do_prompt || the_is_set)
  67.     {
  68.       io_error_msg ("Command '%s' is not appropriate now.",
  69.             cur_cmd->func_name);
  70.       /* not reached */
  71.     }
  72.   return 0;
  73. }
  74.  
  75. /* Set the currently-being-editted line. 
  76.  *
  77.  * When this function is called, it indicates that some argument
  78.  * is being read interactively from the user.  That fact is recorded
  79.  * in the command frame because it relevant to error handling.
  80.  * (See cmd_error in cmd.c)
  81.  *
  82.  */
  83. #ifdef __STDC__
  84. void
  85. begin_edit (void)
  86. #else
  87. void
  88. begin_edit ()
  89. #endif
  90. {
  91.   topclear = 0;
  92.   the_cmd_frame->complex_to_user = 1;
  93.   io_fix_input ();
  94. }
  95.  
  96. #ifdef __STDC__
  97. void
  98. setn_edit_line (char * str, int len)
  99. #else
  100. void
  101. setn_edit_line (str, len)
  102.      char * str;
  103.      int len;
  104. #endif
  105. {
  106.   setn_line (&the_text, str, len);
  107.   the_cursor = len;
  108. }
  109.  
  110. #ifdef __STDC__
  111. void
  112. toggle_overwrite (int set, int setting)
  113. #else
  114. void
  115. toggle_overwrite (set, setting)
  116.      int set;
  117.      int setting;
  118. #endif
  119. {
  120.   if (!set)
  121.     the_overwrite = !the_overwrite;
  122.   else
  123.     the_overwrite = (setting > 0);
  124. }
  125.  
  126. #ifdef __STDC__
  127. void
  128. beginning_of_line (void)
  129. #else
  130. void
  131. beginning_of_line ()
  132. #endif
  133. {
  134.   if (check_editting_mode ())
  135.     return;
  136.   the_cursor = 0;
  137.   io_move_cursor ();
  138. }
  139.  
  140.  
  141. #ifdef __STDC__
  142. void
  143. end_of_line (void)
  144. #else
  145. void
  146. end_of_line ()
  147. #endif
  148. {
  149.   if (check_editting_mode ())
  150.     return;
  151.   the_cursor = strlen (the_text.buf);
  152.   io_move_cursor ();
  153. }
  154.  
  155. #ifdef __STDC__
  156. void
  157. backward_char (int n)
  158. #else
  159. void
  160. backward_char (n)
  161.      int n;
  162. #endif
  163. {
  164.   if (check_editting_mode ())
  165.     return;
  166.   if (n < 0)
  167.     forward_char (-n);
  168.   else
  169.     {
  170.       char * error = 0;
  171.       if (the_cursor < n)
  172.     {
  173.       error = "Beginning of buffer.";
  174.       the_cursor = 0;
  175.     }
  176.       else
  177.     the_cursor -= n;
  178.       io_move_cursor ();
  179.       if (error)
  180.     io_error_msg (error);    /* Doesn't return. */
  181.     }
  182. }
  183.  
  184. #ifdef __STDC__
  185. void
  186. backward_word (int n)
  187. #else
  188. void
  189. backward_word (n)
  190. #endif
  191. {
  192.   if (check_editting_mode ())
  193.     return;
  194.   if (n < 0)
  195.     forward_word (-n);
  196.   else
  197.     {
  198.       if (the_cursor == strlen (the_text.buf))
  199.     --the_cursor;
  200.       while (n)
  201.     {
  202.       while (the_cursor
  203.          && !isalnum (the_text.buf[the_cursor]))
  204.         --the_cursor;
  205.       while (the_cursor
  206.          && isalnum (the_text.buf[the_cursor]))
  207.         --the_cursor;
  208.       --n;
  209.     }
  210.       io_move_cursor ();
  211.     }
  212. }
  213.  
  214.  
  215. #ifdef __STDC__
  216. void
  217. forward_char (int n)
  218. #else
  219. void
  220. forward_char (n)
  221.      int n;
  222. #endif
  223. {
  224.   if (check_editting_mode ())
  225.     return;
  226.   if (n < 0)
  227.     backward_char (-n);
  228.   else
  229.     {
  230.       char * error = 0;
  231.       int len = strlen(the_text.buf);
  232.       if ((the_cursor + n) > len)
  233.     {
  234.       error = "End of buffer.";
  235.       the_cursor = len;
  236.     }
  237.       else
  238.     the_cursor += n;
  239.       io_move_cursor ();
  240.       if (error)
  241.     io_error_msg (error);    /* Doesn't return. */
  242.     }
  243. }
  244.  
  245.  
  246. #ifdef __STDC__
  247. void
  248. goto_char (int n)
  249. #else
  250. void
  251. goto_char (n)
  252.      int n;
  253. #endif
  254. {
  255.   if ((n < 0) || (n > (strlen (the_text.buf))))
  256.     io_error_msg ("Char out of range (%d)", n);
  257.   the_cursor = n;
  258.   io_move_cursor ();
  259. }
  260.  
  261. #ifdef __STDC__
  262. void
  263. forward_word (int n)
  264. #else
  265. void
  266. forward_word (n)
  267.      int n;
  268. #endif
  269. {
  270.   if (check_editting_mode ())
  271.     return;
  272.   if (n < 0)
  273.     backward_word (-n);
  274.   else
  275.     {
  276.       int len = strlen (the_text.buf);
  277.       while (n)
  278.     {
  279.       while ((the_cursor < len)
  280.          && !isalnum (the_text.buf[the_cursor]))
  281.         ++the_cursor;
  282.       while ((the_cursor < len)
  283.          && isalnum (the_text.buf[the_cursor]))
  284.         ++the_cursor;
  285.       --n;
  286.     }
  287.       io_move_cursor ();
  288.     }
  289. }
  290.  
  291.  
  292. #ifdef __STDC__
  293. static void
  294. erase (int len)
  295. #else
  296. static void
  297. erase (len)
  298.      int len;
  299. #endif
  300. {
  301.   if (check_editting_mode ())
  302.     return;
  303.   else
  304.     {
  305.       strcpy (&the_text.buf[the_cursor],
  306.           &the_text.buf[the_cursor + len]);
  307.       io_erase (len);
  308.     }
  309. }
  310.  
  311.  
  312. #ifdef __STDC__
  313. void
  314. backward_delete_char (int n)
  315. #else
  316. void
  317. backward_delete_char (n)
  318. #endif
  319. {
  320.   if (check_editting_mode ())
  321.     return;
  322.   if (n < 0)
  323.     delete_char (-n);
  324.   else
  325.     {
  326.       char * error = 0;
  327.       if (the_cursor < n)
  328.     {
  329.       error = "Beginning of buffer.";
  330.       n = the_cursor;
  331.     }
  332.       the_cursor -= n;
  333.       erase (n);
  334.       if (error)
  335.     io_error_msg (error);    /* Doesn't return. */
  336.     }
  337. }
  338.  
  339.  
  340. #ifdef __STDC__
  341. void 
  342. backward_delete_word (int n)
  343. #else
  344. void 
  345. backward_delete_word (n)
  346. #endif
  347. {
  348.   if (check_editting_mode ())
  349.     return;
  350.   else
  351.     {
  352.       int at = the_cursor;
  353.       while (n)
  354.     {
  355.       while (the_cursor
  356.          && !isalnum (the_text.buf[the_cursor]))
  357.         --the_cursor;
  358.  
  359.       while (the_cursor
  360.          && isalnum (the_text.buf[the_cursor - 1]))
  361.         --the_cursor;
  362.       --n;
  363.     }
  364.       erase (at - the_cursor);
  365.     }
  366. }
  367.  
  368.  
  369. #ifdef __STDC__
  370. void
  371. delete_to_start(void)
  372. #else
  373. void
  374. delete_to_start()
  375. #endif
  376. {
  377.   if (check_editting_mode ())
  378.     return;
  379.   else
  380.     {
  381.       int at = the_cursor;
  382.       the_cursor = 0;
  383.       erase (at);
  384.     }
  385. }
  386.  
  387.  
  388. #ifdef __STDC__
  389. void
  390. delete_char (int n)
  391. #else
  392. void
  393. delete_char (n)
  394.      int n;
  395. #endif
  396. {
  397.   if (check_editting_mode ())
  398.     return;
  399.   if (n < 0)
  400.     backward_delete_char (-n);
  401.   else
  402.     {
  403.       char * error = 0;
  404.       int len = strlen (the_text.buf);
  405.       if (the_cursor + n > len)
  406.     {
  407.       error = "End of buffer.";
  408.       n = len - the_cursor;
  409.     }
  410.       erase (n);
  411.       if (error)
  412.     io_error_msg (error);    /* Doesn't return. */
  413.     }
  414. }
  415.  
  416. #ifdef __STDC__
  417. void
  418. delete_word (int n)
  419. #else
  420. void
  421. delete_word (n)
  422.      int n;
  423. #endif
  424. {
  425.   if (check_editting_mode ())
  426.     return;
  427.   if (n < 0)
  428.     backward_delete_word (-n);
  429.   else
  430.     {
  431.       int len = strlen (the_text.buf);
  432.       int erase_len = 0;
  433.       while (n)
  434.     {
  435.       while (((the_cursor + erase_len) < len)
  436.          && !isalnum (the_text.buf[(the_cursor + erase_len)]))
  437.         ++erase_len;
  438.       while (((the_cursor + erase_len) < len)
  439.          && isalnum (the_text.buf[(the_cursor + erase_len)]))
  440.         ++erase_len;
  441.       --n;
  442.     }      
  443.       erase (erase_len);
  444.     }
  445. }
  446.  
  447.  
  448. #ifdef __STDC__
  449. void
  450. kill_line(void)
  451. #else
  452. void
  453. kill_line()
  454. #endif
  455. {
  456.   if (check_editting_mode ())
  457.     return;
  458.   else
  459.     {
  460.       int len = strlen (the_text.buf);
  461.       erase (len - the_cursor);
  462.     }
  463. }
  464.  
  465. #ifdef __STDC__
  466. void
  467. insert_string (char * str, int len)
  468. #else
  469. void
  470. insert_string (str, len)
  471.      char * str;
  472.      int len;
  473. #endif
  474. {
  475.   if (check_editting_mode ())
  476.     return;
  477.   splicen_line (&the_text, str, len, the_cursor);
  478.   io_insert (len);
  479.   the_cursor += len;
  480. }
  481.  
  482. #ifdef __STDC__
  483. void
  484. over_string (char * str, int len)
  485. #else
  486. void
  487. over_string (str, len)
  488.      char * str;
  489.      int len;
  490. #endif
  491. {
  492.   if (check_editting_mode ())
  493.     return;
  494.   if (the_cursor + len > strlen (the_text.buf))
  495.     {
  496.       catn_line (&the_text, str + the_text.alloc - the_cursor,
  497.          len - (the_text.alloc - the_cursor));
  498.       len = the_text.alloc - the_cursor;
  499.     }
  500.   if (len)
  501.     bcopy (str, the_text.buf + the_cursor, len);
  502.   io_over (str, len);
  503.   the_cursor += len;
  504. }
  505.  
  506. #ifdef __STDC__
  507. void
  508. put_string (char * str, int len)
  509. #else
  510. void
  511. put_string (str, len)
  512.      char * str;
  513.      int len;
  514. #endif
  515. {
  516.   if (check_editting_mode ())
  517.     return;
  518.   (the_overwrite ? over_string : insert_string) (str, len);
  519. }
  520.  
  521.  
  522.  
  523. /* Higher Level editting commands. */
  524.  
  525. #ifdef __STDC__
  526. void
  527. insert_cell_expression (void)
  528. #else
  529. void
  530. insert_cell_expression ()
  531. #endif
  532. {
  533.   if (check_editting_mode ())
  534.     return;
  535.   else
  536.     {
  537.       CELL *cp;
  538.       char * in_str;
  539.       if (!(cp = find_cell (curow, cucol)))
  540.     return;
  541.       in_str = decomp (curow, cucol, cp);
  542.       put_string (in_str, strlen(in_str));
  543.       decomp_free ();
  544.     }
  545. }
  546.  
  547.  
  548. #ifdef __STDC__
  549. void
  550. insert_cell_value(void)
  551. #else
  552. void
  553. insert_cell_value()
  554. #endif
  555. {
  556.   if (check_editting_mode ())
  557.     return;
  558.   else
  559.     {
  560.       char * in_str;
  561.       in_str = cell_value_string (curow, cucol);
  562.       put_string (in_str, strlen(in_str));
  563.     }
  564. }
  565.  
  566. #ifdef __STDC__
  567. void
  568. insert_rel_ref(void)
  569. #else
  570. void
  571. insert_rel_ref()
  572. #endif
  573. {
  574.   if (check_editting_mode ())
  575.     return;
  576.   else
  577.     {
  578.       char vbuf[50];
  579.       char * in_str;
  580.       if (a0)
  581.     {
  582.       if (mkrow != NON_ROW)
  583.         {
  584.           struct rng r;
  585.           set_rng (&r, curow, cucol, mkrow, mkcol);
  586.           in_str = range_name (&r);
  587.         }
  588.       else
  589.         in_str = cell_name (curow, cucol);
  590.     }
  591.       else
  592.     {
  593.       if (mkrow != NON_ROW)
  594.         {
  595.           switch (((curow == setrow) << 3)
  596.               + ((mkrow == setrow) << 2)
  597.               + ((cucol == setcol) << 1)
  598.               + (mkcol == setcol))
  599.         {
  600.         case 0:
  601.         case 1:
  602.         case 2:
  603.         case 4:
  604.         case 5:
  605.         case 6:
  606.         case 8:
  607.         case 9:
  608.         case 10:
  609.           sprintf (vbuf, "r[%+d:%+d]c[%+d:%+d]",
  610.                (curow < mkrow ? curow : mkrow) - setrow,
  611.                (curow < mkrow ? mkrow : curow) - setrow,
  612.                (cucol < mkcol ? cucol : mkcol) - setcol,
  613.                (cucol < mkcol ? mkcol : cucol) - setcol);
  614.           break;
  615.           
  616.         case 3:
  617.         case 7:
  618.         case 11:
  619.           sprintf (vbuf, "r[%+d:%+d]c",
  620.                (curow < mkrow ? curow : mkrow) - setrow,
  621.                (curow < mkrow ? mkrow : curow) - setrow);
  622.           break;
  623.           
  624.         case 12:
  625.         case 14:
  626.         case 13:
  627.           sprintf (vbuf, "rc[%+d:%+d]",
  628.                (cucol < mkcol ? cucol : mkcol) - setcol,
  629.                (cucol < mkcol ? mkcol : cucol) - setcol);
  630.           break;
  631.           
  632.         case 15:
  633.           strcpy (vbuf, "rc");
  634.           break;
  635.         }
  636.         }
  637.       
  638.       else
  639.         {
  640.           switch (((curow == setrow) << 1) + (cucol == setcol))
  641.         {
  642.         case 0:
  643.           sprintf (vbuf, "r[%+d]c[%+d]", curow - setrow, cucol - setcol);
  644.           break;
  645.         case 1:
  646.           sprintf (vbuf, "r[%+d]c", curow - setrow);
  647.           break;
  648.         case 2:
  649.           sprintf (vbuf, "rc[%+d]", cucol - setcol);
  650.           break;
  651.         case 3:
  652.           strcpy (vbuf, "rc");
  653.           break;
  654. #ifdef TEST
  655.         default:
  656.           panic ("huh what");
  657. #endif
  658.         }
  659.         }
  660.       in_str = vbuf;
  661.     }
  662.       put_string (in_str, strlen (in_str));
  663.     }
  664. }
  665.  
  666.  
  667. #ifdef __STDC__
  668. void
  669. insert_abs_ref(void)
  670. #else
  671. void
  672. insert_abs_ref()
  673. #endif
  674. {
  675.   if (check_editting_mode ())
  676.     return;
  677.   else
  678.     {
  679.       char vbuf[50];
  680.       char * in_str;
  681.       /* Insert current cell/range name as an absolute reference */
  682.       if (a0)
  683.     {
  684.       if (mkrow != NON_ROW)
  685.         sprintf (vbuf, "$%s$%u:$%s:$%u",
  686.              col_to_str (cucol), curow, col_to_str (mkcol), mkrow) ;
  687.       else
  688.         sprintf (vbuf, "$%s$%u", col_to_str (cucol), curow);
  689.       in_str = vbuf;
  690.     }
  691.       else
  692.     {
  693.       if (mkrow != NON_ROW)
  694.         {
  695.           struct rng r;
  696.           
  697.           set_rng (&r, curow, cucol, mkrow, mkcol);
  698.           in_str = range_name (&r);
  699.         }
  700.       else
  701.         in_str = cell_name (curow, cucol);
  702.     }
  703.       put_string (in_str, strlen (in_str));  
  704.     }
  705. }
  706.  
  707. #ifdef __STDC__
  708. void
  709. insert_cell_attr (struct rng * rng, char * attr)
  710. #else
  711. void
  712. insert_cell_attr (rng, attr)
  713.      struct rng * rng;
  714.      char * attr;
  715. #endif
  716. {
  717.   struct line line;
  718.   init_line (&line);
  719.   if (!stricmp (attr, "width"))
  720.     {
  721.       int wid = get_nodef_width (rng->lc);
  722.       if (wid == 0)
  723.     set_line (&line, "def");
  724.       else
  725.     sprint_line (&line, "%d", wid - 1);
  726.     }
  727.   else if (!stricmp (attr, "height"))
  728.     {
  729.       int hgt = get_nodef_height (rng->lr);
  730.       if (hgt == 0)
  731.     set_line (&line, "def");
  732.       else
  733.     sprint_line (&line, "%d", hgt - 1);
  734.     }
  735.   else if (!stricmp (attr, "format"))
  736.     {
  737.       CELL * cp = find_cell (rng->lr, rng->lc);
  738.       if (!cp)
  739.     set_line (&line, "def");
  740.       else
  741.     {
  742.       int fmt = GET_FMT (cp);
  743.       set_line (&line, fmt_to_str (fmt));
  744.     }
  745.     }
  746.   else if (!stricmp (attr, "font"))
  747.     {
  748.       CELL * cp = find_cell (rng->lr, rng->lc);
  749.       if (!(cp && cp->cell_font))
  750.     set_line (&line, "def");
  751.       else
  752.     set_line (&line, cp->cell_font->names->oleo_name);
  753.     }
  754.   else if (!stricmp (attr, "font-scale"))
  755.     {
  756.       CELL * cp = find_cell (rng->lr, rng->lc);
  757.       if (!(cp && cp->cell_font))
  758.     set_line (&line, "1.0");
  759.       else
  760.     sprint_line (&line, "%lf", cp->cell_font->scale);
  761.     }
  762.   put_string (line.buf, strlen (line.buf));
  763. }
  764.  
  765. #ifdef __STDC__
  766. void
  767. insert_usr_fmt_part (int fmt, int stat)
  768. #else
  769. void
  770. insert_usr_fmt_part (fmt, stat)
  771.      int fmt;
  772.      int stat;
  773. #endif
  774. {
  775.   char * usr_stats[9];
  776.   if ((fmt < 1) || (fmt > 16))
  777.     io_error_msg
  778.       ("insert-user-format-part arg 1 out of range (%d); should be in [1-16].",
  779.        fmt);
  780.   --fmt;
  781.   if ((stat < 1) || (stat > 16))
  782.     io_error_msg
  783.       ("insert-user-format-part arg 2 out of range (%d); should be in [1-9].",
  784.        stat);
  785.   --stat;
  786.   get_usr_stats (fmt, usr_stats);
  787.   put_string (usr_stats[stat], strlen (usr_stats[stat]));
  788. }
  789.  
  790. #ifdef __STDC__
  791. void
  792. self_insert_command (int ch, int count)
  793. #else
  794. void
  795. self_insert_command (ch, count)
  796.      int ch;
  797.      int count;
  798. #endif
  799. {
  800.   if (check_editting_mode ())
  801.     return;
  802.   else if (count == 1)
  803.     {
  804.       char chr = ch;
  805.       put_string (&chr, 1);
  806.     }
  807.   else if (count > 0)
  808.     {
  809.       char * buf = (char *)ck_malloc (count); /* sleazy, huh? */
  810.       int x;
  811.       for (x = 0; x < count; ++x)
  812.     buf[x] = ch;
  813.       put_string (buf, count);
  814.     }
  815. }
  816.  
  817.  
  818. /* Keysequences are read using the `keyseq' keymap.
  819.  * Every key in that map should be bound to this function.
  820.  */
  821. #ifdef __STDC__
  822. void
  823. self_map_command (int c)
  824. #else
  825. void
  826. self_map_command (c)
  827.      int c;
  828. #endif
  829. {
  830.   struct keymap * map = the_maps[the_cmd_arg.val.key.cmd.code];
  831.   char space = ' ';
  832.   char * str = char_to_string (c);
  833.  
  834.   insert_string (str, strlen (str));
  835.   insert_string (&space, 1);
  836.  
  837.   while (map)
  838.     {
  839.       the_cmd_arg.val.key.cmd = map->keys[c];
  840.       if (the_cmd_arg.val.key.cmd.vector < 0)
  841.     {
  842.       if (the_cmd_arg.val.key.cmd.code < 0)
  843.         map = map->map_next;
  844.       else
  845.         return;
  846.     }
  847.       else
  848.     break;
  849.     }
  850.   exit_minibuffer ();
  851.   return;
  852. }
  853.  
  854. #ifdef __STDC__
  855. void
  856. insert_current_filename (void)
  857. #else
  858. void
  859. insert_current_filename ()
  860. #endif
  861. {
  862.   if (current_filename)
  863.     put_string (current_filename, strlen (current_filename));
  864. }
  865.  
  866.  
  867. /* Reading a single character is done with the read-char
  868.  * map.  Every key in that map should be bound to this function.
  869.  */
  870. #ifdef __STDC__
  871. void
  872. exit_self_inserting (int c)
  873. #else
  874. void
  875. exit_self_inserting (c)
  876.      int c;
  877. #endif
  878. {
  879.   char * str = char_to_string (c);
  880.  
  881.   insert_string (str, strlen (str));
  882.   exit_minibuffer ();
  883. }
  884.  
  885.  
  886. #ifdef __STDC__
  887. static int
  888. issymb (int c)
  889. #else
  890. static int
  891. issymb (c)
  892.      int c;
  893. #endif
  894. {
  895.   return isalpha (c) || isdigit (c) || (c == '_');
  896. }
  897.  
  898. #undef the_text
  899. #undef the_cursor
  900. #undef the_do_prompt
  901. #ifdef __STDC__
  902. void
  903. insert_context_word (void)
  904. #else
  905. void
  906. insert_context_word ()
  907. #endif
  908. {
  909.   struct command_frame * cf = the_cmd_frame->prev;
  910.   if (   (cf == the_cmd_frame)
  911.       || !cf->cmd
  912.       || !cf->argv [cf->_cur_arg].do_prompt)
  913.     return;
  914.   {
  915.     struct command_arg * ca = &cf->argv [cf->_cur_arg];
  916.     char * beg_text = ca->text.buf;
  917.     char * last = beg_text + ca->cursor;
  918.     char * start;
  919.  
  920.     while ((last > beg_text) && !issymb(*last))
  921.       --last;
  922.     while (*last && issymb (*last))
  923.       ++last;
  924.     --last;
  925.     start = last;
  926.     while ((start > beg_text) && issymb(*start))
  927.       --start;
  928.     if (!issymb (*start) && (start < last))
  929.       ++start;
  930.  
  931.     if ((start <= last) && issymb (*start))
  932.       {
  933.     insert_string (start, last - start + 1);
  934.     the_cmd_arg.cursor = 0;
  935.       }
  936.   }
  937. }
  938.